package com.talent.jiwen_teacher;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.talent.jiwen_teacher.base.BaseActivity;
import com.talent.jiwen_teacher.helper.ViewPagerAdatper;

import java.util.ArrayList;

import butterknife.BindView;


/**
 * Created by qyqx on 2018/8/15.
 */

public class GuideActivity extends BaseActivity implements ViewPager.OnPageChangeListener{

    @BindView(R.id.in_viewpager)
    ViewPager vPager;

    @BindView(R.id.img_go)
    ImageView img_go;

    private ViewPagerAdatper vpAdapter;
    private static  int[] imgs = {R.mipmap.guide_1,R.mipmap.guide_2, R.mipmap.guide_3};
    private ArrayList<ImageView> imageViews;


    @Override
    protected int provideContentViewId() {
        return R.layout.activity_guide;
    }

    @Override
    public String titleName() {
        return null;
    }

    @Override
    protected void initData() {
        setHeadVisibility(View.GONE);

//        vpAdapter=new ViewPagerAdatper()

        //设置每一张图片都填充窗口
        ViewPager.LayoutParams mParams = new ViewPager.LayoutParams();
        imageViews = new ArrayList<ImageView>();

        for(int i=0; i<imgs.length; i++)
        {
            ImageView iv = new ImageView(this);
            iv.setLayoutParams(mParams);//设置布局
            iv.setImageResource(imgs[i]);//为ImageView添加图片资源
            iv.setScaleType(ImageView.ScaleType.FIT_XY);//这里也是一个图片的适配
            imageViews.add(iv);
//            if (i == imgs.length -1 ){
//                //为最后一张图片添加点击事件
//                iv.setOnTouchListener(new View.OnTouchListener(){
//                    @Override
//                    public boolean onTouch(View v, MotionEvent event){
//                        Intent toMainActivity = new Intent(GuideActivity.this, LoginActivity.class);//跳转到主界面
//                        startActivity(toMainActivity);
//                        return true;
//                    }
//                });
//            }
        }

        vpAdapter=new ViewPagerAdatper(imageViews);
//        vPager.setPageTransformer(true,new DepthPageTransformer());
        vPager.setAdapter(vpAdapter);
        vPager.setOnPageChangeListener(this);

    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    }

    @Override
    public void onPageSelected(int position) {
        if(position==2){
            img_go.setVisibility(View.VISIBLE);
            img_go.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent toMainActivity = new Intent(GuideActivity.this, LoginActivity.class);//跳转到主界面
                    startActivity(toMainActivity);
                    finish();
                }
            });
        }else{
            img_go.setVisibility(View.GONE);
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
